import json

"""python中读取文件中的内容，并更修改"""
with open("flag.json",'rb') as f:
    # 获取json文件对象
    loads = json.loads(f.read())
    print(loads)
    # 逐个遍历数组中的对象，更改数组中对应对象的值
    for item in loads['testcase_name']:
        # 修改某个属性
        if item['name'] == "aaa" :
            item['params']['targetConfig']['table'] = "xxx"
        # 追加新属性
        item['params']['targetConfig']['table2'] = "xxx2"
    # 写入到目标文件    
print(loads)
with open("change.json","w") as f:
    json.dump(loads,f)
    print("-------success----------")